import Vue from 'vue'
import Router from 'vue-router'
import { getSStore } from "../utils/util"

const Home = resolve => require(['@/pages/home/home'], resolve)
const Login = resolve => require(['@/pages/login/login'], resolve)
const View = resolve => require(['@/components/View'], resolve)
//订单管理
const FlightOrders = resolve => require(['@/pages/orderManage/flight/flightOrder'], resolve)
const FlightOrderDetail = resolve => require(['@/pages/orderDetail/flight/flightOrderDetail'], resolve)

const HotelOrders = resolve => require(['@/pages/orderManage/hotel/hotelOrder'], resolve)
const HotelOrderDetail = resolve => require(['@/pages/orderDetail/hotel/hotelOrderDetail'], resolve)

const TrainOrders = resolve => require(['@/pages/orderManage/train/trainOrder'], resolve)
const TrainOrderDetail = resolve => require(['@/pages/orderDetail/train/trainOrderDetail'], resolve)



//机票
const FlightShopping = resolve => require(['@/pages/flight/shopping/shopping'], resolve)
const FlightOrder = resolve => require(['@/pages/flight/order/order'], resolve)
//火车
const TrainShopping = resolve => require(['@/pages/train/shopping/shopping'], resolve)
const TrainOrder = resolve => require(['@/pages/train/order/order'], resolve)
//酒店





//机票火车酒店支付页
const Pay = resolve => require(['@/components/pay/pay'], resolve)
//财务管理
const FinanceManage = resolve => require(['@/pages/financeManage/financeManage'], resolve)
//报表中心
const ReportCenter = resolve => require(['@/pages/reportCenter/reportCenter'], resolve)

Vue.use(Router)

let router = new Router({
  routes: [
  	{
      path: '/',
      name: 'login',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/flight',
      name: '机票',
      component: View,
      redirect: '/flight/shopping',
      children:[
				{ path: '/flight/shopping', component: FlightShopping, name: '航班列表', },
				{ path: '/flight/order', component: FlightOrder, name: '航班订单', },
				{ path: '/flight/pay', component: Pay, name: '机票订单支付', },
			]
    },{
      path: '/train',
      name: '火车',
      component: View,
      redirect: '/train/shopping',
      children:[
				{ path: '/train/shopping', component: TrainShopping, name: '火车列表', },
				{ path: '/train/order', component: TrainOrder, name: '火车订单', },
				{ path: '/train/pay', component: Pay, name: '火车订单支付', },
			]
    },{
      path: '/hotel',
      name: '酒店',
      component: View,
      redirect: '/hotel/shopping',
      children:[
				{ path: '/hotel/shopping', component: View, name: '酒店列表', },
				{ path: '/hotel/order', component: View, name: '住宿订单', },
				{ path: '/hotel/pay', component: View, name: '酒店订单支付', },
			]
    },
    {
      path: '/orderManage',
      name: '订单管理',
      component: View,
      level:1,
      children:[
      	{path: '/orderManage/flight',name: '机票订单',component: FlightOrders,level:2,},
      	{path: '/orderManage/flight/detail',name: '机票订单详情',component: FlightOrderDetail},
      	{path: '/orderManage/hotel',name: '酒店订单',component: HotelOrders,level:2,},
      	{path: '/orderManage/hotel/detail',name: '酒店订单详情',component: HotelOrderDetail},
      	{path: '/orderManage/train',name: '火车票订单',component: TrainOrders,level:2,},
      	{path: '/orderManage/train/detail',name: '火车订单详情',component: TrainOrderDetail},
      ]
    },
    
    {
      path: '/financeManage',
      name: '财务管理',
      component: FinanceManage,
      level:1,
      leaf:true,
    },
    {
      path: '/reportCenter',
      name: '报表中心',
      component: ReportCenter,
      level:1,
      leaf:true,
    },
  ]
})
//登录拦截
router.beforeEach((to, from, next) => {
	let user = getSStore('user')
	if(user || to.path == "/") {
		next()
	} else {
		next({ path: '/' })
	}
})

export default router;